import { INC } from '../../mutation-types';

let counter={
  namespaced:true,//开启命名空间
  state:{
    count:10,
    users:[
      {id:1,name:"张三",age:18},
      {id:2,name:"李四",age:22},
      {id:3,name:"王五",age:25},
      {id:4,name:"赵六",age:26}
    ]
  },
  getters:{
    /*
       第一个参数：本模块中的state
       第二个参数：其他 getter
       第三个参数：所有模块的state
       */
    getUsers(state,getters,rootState){
      let users=state.users.filter(res=>res.age>18);
      return users;
    }
  },
  mutations:{
    [INC](state,payload){
      // console.log(state,payload);
      state.count+=payload.amount;
    }
  },
  actions:{
    // asyncInc(conText,payload){
    //   // console.log(conText,payload)
    //   setTimeout(()=>{
    //     conText.commit(INC,payload)
    //   },30)
    // }
    asyncInc({commit3},payload){
      // console.log(conText,payload)
      setTimeout(()=>{
        commit(INC,payload)
      },30)
    }
  }
}
export default counter;
